﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using Gift.DAL;
using Gift.Model;
using Gift.Utile;
using System.Text;

namespace WebSite.cn
{
    public partial class products_details : BasePage
    {
         // Fields

        StringBuilder sbNavigater = new StringBuilder();

        public StringBuilder SbNavigater
        {
            get { return sbNavigater; }

        }
    public string clicks = "0";

    public string h3 = "0";
    public string h4 = "0";


    public string images = "";
    public string imgs = "";

    public string pic = "";
    public string price = "0";
    public string procode = "";

    public string proimg = "";
    public string proname = "";
    public string propinpai = "";
    public string proprice1 = "0";
    public string proprice3 = "0";
    public string proscore = "0";
    public string typename = "";

    public string proku1 = string.Empty;

    public string SPriceName = "";
    public string Instruction = "";

    readonly DALShoppro theShoppro = new DALShoppro();

    // Methods
    private void Bind()
    {
        

        DataTable table = SQLAccess.GreatDs("select proid,typeid,proname,iscuxao,procode,propinpai, proku1,procontent,Instruction,proprice4,proprice1,prokey,proprice3,propic1,proscore1,propic2,clicks,proisnew3,proisnew2,proisnew4,professionAreaTypeId from DB_Shoppro where proid=" + base.Request.QueryString["pid"] + "").Tables[0];
        if (table.Rows.Count > 0)
        {


            if (table.Rows[0]["proisnew2"].ToString().ToString().ToLower() == "true")
            {
                tbProfessionAreaType oType = new DALProfessionAreaType().GetModel(int.Parse(table.Rows[0]["professionAreaTypeId"].ToString()));
                if (oType != null)
                {
                    sbNavigater.Append("所在位置 > <a href='hotpro.aspx?sid=2'>专区商品</a> > <a href='ProfessionArea.aspx?sid=2&typeid=" + table.Rows[0]["professionAreaTypeId"].ToString() + "'>" + oType.Name + "</a>");
                }
            }

            this.proname = table.Rows[0]["proname"].ToString();
            this.procode = table.Rows[0]["procode"].ToString();
            this.proprice3 = string.Format("{0:f}", table.Rows[0]["proprice3"]);
            this.proprice1 = string.Format("{0:f}", table.Rows[0]["proprice1"]);
            this.price = table.Rows[0]["proprice1"].ToString();
            this.SPriceName = table.Rows[0]["proisnew3"].ToString().ToString().ToLower() == "true" ? "零售价：" : "兑换价：";
            if (table.Rows[0]["proisnew2"].ToString().ToString().ToLower() == "false")
            {
                this.ibtnSubmit.Visible = false;
            }
            this.proscore = table.Rows[0]["proscore1"].ToString();
            this.Instruction = table.Rows[0]["Instruction"].ToString();
            this.proku1 = table.Rows[0]["proku1"].ToString();
            string str3 = Displaya(table.Rows[0]["typeid"].ToString(), "1");
            if (str3.ToString() != "")
            {
              
                string[] strArray = str3.ToString().Split(new char[] { '|' });
                for (int i = strArray.Length - 1; i >= 0; i--)
                {
                    DataTable table2 = SQLAccess.GreatDs("select classname,classid from DB_Productclass where classid=" + strArray[i] + "").Tables[0];
                    if (table.Rows.Count > 0)
                    {
                        if (table.Rows[0]["typeid"].ToString() == strArray[i].ToString())
                        {
                            sbNavigater.Append( "<span class='text_red03'>" + table2.Rows[0]["classname"].ToString() + "</span>");
                        }
                        else
                        {    
                           if (table.Rows[0]["proisnew4"].ToString().ToString().ToLower() == "true")
                            {
                                sbNavigater.Append("所在位置 > <a href='hotpro.aspx?sid=4'>商城商品</a> > <a href='hotpro.aspx?sid=4&typeid=" + table2.Rows[0]["classid"].ToString() + "'>" + table2.Rows[0]["classname"].ToString() + "</a>");
                            }
                            else 
                            {
                                sbNavigater.Append(" 所在位置 > <a href='hotpro.aspx?sid=3'>卡展示区</a>  > <a href='hotpro.aspx?sid=3&typeid=" + table2.Rows[0]["classid"].ToString() + "'>" + table2.Rows[0]["classname"].ToString() + "</a>");
                            }
                        }
      
                    }
                }
            }
            if (Convert.ToBoolean(table.Rows[0]["iscuxao"]))
            {
                this.proprice1 = string.Format("{0:f}", table.Rows[0]["proprice4"]);
                this.price = table.Rows[0]["proprice4"].ToString();
            }
        
            this.images = "../../uploadfile/product/" + table.Rows[0]["propic1"].ToString();
            this.proimg = "../../uploadfile/product/" + table.Rows[0]["propic1"].ToString();
            this.clicks = table.Rows[0]["clicks"].ToString();
            this.imgs = "<SCRIPT>";
            string pic = this.pic;
            this.pic = pic + "<TD id=original_image onmouseover=displayImage('original_image','../../uploadfile/product/" + table.Rows[0]["propic1"].ToString() + "') class=border_2  width=20%><TABLE cellSpacing=0 cellPadding=0 border=0><TR><TD><A  href='pic.aspx?pid=" + table.Rows[0]["proid"].ToString() + "' target=_blank><IMG   src='../../uploadfile/product/" + table.Rows[0]["propic2"].ToString() + "' width=60px; border=0></A></TD></TR></TABLE></TD>";
            DataTable table3 = SQLAccess.GreatDs("select * from DB_Shoppic where proid=" + re.replace(base.Request.QueryString["pid"]) + " order by picid asc").Tables[0];
            if (table3.Rows.Count > 0)
            {
                int num3 = 1;
                foreach (DataRow row in table3.Rows)
                {
                    object obj6 = this.pic;
                    this.pic = string.Concat(new object[] { obj6, "<TD id=cust_image_", num3, "  onmouseover=displayImage('cust_image_", num3, "','../../uploadfile/", row["picurl"].ToString().Replace(@"\", "/"), "') class=border_1 width=25%><TABLE cellSpacing=0 cellPadding=0 border=0><TR><TD><A  href=pic1.aspx?pid=", row["proid"], "&picid=", row["picid"], " target=_blank><IMG  src=../../uploadfile/", row["picurl"], " width=60 border=0></A></TD></TR></TABLE></TD> " });
                    object imgs = this.imgs;
                    this.imgs = string.Concat(new object[] { 
                        imgs, "registerImage('cust_image_", num3, "', '../../uploadfile/", row["picurl"].ToString().Replace(@"\", "/"), "', '<a href=pic1.aspx?pid=", row["proid"], "&picid=", row["picid"], " target=_blank><img src=../../uploadfile/", row["picurl"].ToString().Replace(@"\", "/"), "  width=", Convert.ToSingle(this.h3), " height=", Convert.ToSingle(this.h4), " border=0 /></a>', '", 
                        row["content"], "');"
                     });
                    num3++;
                    if ((num3 % 4) == 0)
                    {
                        this.pic = this.pic + "</tr><tr>";
                    }
                }
            }
        
            this.imgs = this.imgs + "</SCRIPT>";
        }
    }

    public static string Displaya(string classid, string languages)
    {
        string str2 = "";
        string sql = "select top 1 parentid,classid from DB_Productclass where classid=" + classid + " and languages=" + languages + " and visible= 1 order by classorder";
        DataTable table = new DataTable();
        table = SQLAccess.GreatDs(sql).Tables[0];
        if (table.Rows.Count > 0)
        {
            str2 = str2 + table.Rows[0]["classid"].ToString() + "";
            if (table.Rows[0]["parentid"].ToString() != "0")
            {
                str2 = str2 + "|" + Displaya(table.Rows[0]["parentid"].ToString(), languages);
            }
        }
        return str2.ToString();
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            this.SaveLastBrowesProduct();
            string sql = "Select top 1 shopwidth1,shopheight1 From DB_Shopconfig";
            DataTable table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.h3 = table.Rows[0]["shopwidth1"].ToString();
                this.h4 = table.Rows[0]["shopheight1"].ToString();
            }
            if (base.Request.QueryString["pid"] != null)
            {
                this.Bind();
                SQLAccess.DoSql("update DB_Shoppro set clicks=clicks+1 where proid=" + base.Request.QueryString["pid"] + "");
            }
        }
    }

    string Proid
    {
        get {
            return base.Request.QueryString["pid"];
        }
     }


    void SaveLastBrowesProduct()
    {
        string strSQL = string.Empty;
        strSQL = "If NOT EXISTS(select 1 from tblLastBrowesProduct where proid = {0} and ip = '{1}') ";
        strSQL += "INSERT INTO tblLastBrowesProduct(proid,ip) values({2},'{3}')";
        SQLAccess.DoSql(string.Format(strSQL, Proid, ClientIP, Proid, ClientIP));
     }


    }
}